﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link rel="stylesheet" type="text/css" href="~/layui/css/layui.css" />
    <script src="~/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/layui/jquery-3.4.1.js" type="text/javascript" charset="utf-8"></script>
    <title>兑换历史记录</title>
    <style type="text/css">
        .layui-input {
            margin-top: 5px;
            height: 30px
        }

        .layui-form-label {
            width: auto;
            padding: 5px 10px;
            margin-top: 5px;
        }
    </style>
  
</head>
<body>
    <div>
        <fieldset class="layui-elem-field layui-field-title">
            <legend>查找会员</legend>
            <div class="layui-field-box">
                <div class="layui-form-item">
                    <label class="layui-form-label">会员卡号/手机：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input" id="MC">
                    </div>
                    <button id="searh" type="button" class="layui-btn layui-btn layui-btn-sm" style="margin-top: 5px;"><i class="layui-icon">&#xe615;全部兑换记录</i></button>
                </div>
            </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
            <legend>兑换记录列表</legend>
            <div class="layui-field-box">
                <table class="layui-inline" lay-filter="table" id="ExchangLogs"></table>
            </div>
        </fieldset>
    </div>
    <script>
        //格式化时间列表
          function FormatToDate(val) {
                if (val != null) {
                    var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
                    //月份为0-11，所以+1，月份小于10时补个0
                    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                    return date.getFullYear() + "-" + month + "-" + currentDate;
                }
                return "";
            }
        layui.use(['table', 'layer'], function () {
            var table = layui.table,
                layer = layui.layer;
            //行内工具栏
            table.on('tool(table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            type: "get",
                            url: "/Member/MemcardDelResult",
                            data: { id: data.CL_ID },
                            success: function (data) {
                                if (data == '删除成功') {
                                    layer.msg(data, { icon: 1 })
                                    obj.del();
                                } else {
                                    layer.msg(data, { icon: 2 })
                                }
                            },
                            error: function (data) {
                                layer.msg('删除失败', { icon: 2 })
                            }
                        })
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    // window.location.href='update.aspx?id=' + data.U_ID
                    //layer.alert('编辑行：<br>' + JSON.stringify(data))
                    var id = data.CL_ID;
                    layer.open({
                        type: 2,
                        content: ['/Member/MemcardEdit/' + id + '', 'no'],
                        area: ['500px', '400px'],
                        offset: ['100px', '400px'],
                        skin: 'layui-layer-molv',
                        maxmin: true,
                        id: 'add',
                        end: function () { table.reload('cardList') }
                    });
                }
            });
            //添加按钮点击事件
            $('#new').click(function () {
                layer.open({
                    type: 2,
                    content: ['/Member/MemcardAdd', 'no'],
                    //content: ['/Member/Add', 'no'],
                    area: ['500px', '400px'],
                    offset: ['100px', '400px'],
                    skin: 'layui-layer-molv',
                    maxmin: true,
                    id: 'add',
                    end: function () { table.reload('cardList') }
                });
            })
            //搜索按钮的点击事件
            $('#searh').on('click', function () {
                //获取输入框的值
                var MC_CardID = $('#MC').val();
                //表格重载，并传回服务器参数
                table.reload('ExchangLogs', {
                    //提交方式 Post
                    method: 'post',
                    //传回服务器的参数
                    where: {
                        'MC_CardID': MC_CardID
                    }
                });
            })
            //载入表格
            table.render({
                elem: '#ExchangLogs',
                url: '/ExchangLogs/GetExchangLogsList',
                //开启分页
                page: 'true',
                cols: [
                    [{
                        type: 'numbers'
                    },
                        {
                        field: 'EG_GiftName',
                        width: 150,
                        title: '礼品名称',
                        sort: true
                    },
                    {
                        field: 'EL_Point',
                        width: 150,
                        title: '所需积分',
                        sort: true
                    },
                    {
                        field: 'EL_Number',
                        width: 150,
                        title: '兑换数量',
                        sort: true
                    },
                    {
                        field: 'EL_CreateTime',
                        templet: function (d) { return FormatToDate(d.EL_CreateTime) },
                        width: 200,
                        title: '兑换时间',
                        sort: true,
                        
                    }
                   
                    ]
                ]
            });

        })
    </script>
</body>
</html>
